package acm.pta10;

import java.util.Scanner;

public class 判断题 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] ans = new int[m];
        int[] val = new int[m];
        for (int i = 0; i < m; i++) {
            val[i] = sc.nextInt();
        }
        for (int i = 0; i < m; i++) {
            ans[i] = sc.nextInt();
        }
        while (n-- > 0) {
            int sum = 0;
            for (int i = 0; i < m; i++) {
                if (sc.nextInt() == ans[i]) {
                    sum += val[i];
                }
            }
            System.out.println(sum);
        }
    }
}
